import matplotlib.pyplot as plt
import glob

def readMetaData(dirname):
    filename = glob.glob(dirname + '/*metadata')[0]
    f = open(filename)
    l = []
    for line in f:
        l += [line.split()]
    result = l[3:-1]
    result = [[float(v[0]), float(v[1])] for v in result]
    return result
    

data = readMetaData('attempt4')
stepCount = [v[0] for v in data]
fitness = [v[1] for v in data]

x = []
y = []

for i in range(1, len(stepCount)):
    step = stepCount[i]
    fit = fitness[i]
    if fit < fitness[i - 1]:
        x += [step]
        y += [fitness[i - 1]]
        x += [step]
        y += [fit]
    else:
        x += [step]
        y += [fit]
    
plt.xlabel("Number of fitness function calculations")
plt.ylabel("Value of fitness function")
plt.title("History of fitness function values")
plt.plot(x, y)
plt.show()




    